// Copyright (c) 2023 Huawei Device Co., Ltd.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/// Type of Node.
/// Each variant corresponds to a specific type of node in the XML DOM.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum NodeType {
    /// An element node.
    Element = 1,
    /// An attribute of an Element node.
    Attribute = 2,
    /// A text node.
    Text = 3,
    /// A CDATA section node.
    CdataSection = 4,
    /// An entity reference node.
    EntityReference = 5,
    /// An entity node.
    Entity = 6,
    /// A processing instruction node.
    ProcessingInstruction = 7,
    /// A comment node.
    Comment = 8,
    /// A document node (root of the document tree).
    Document = 9,
    /// A document type node (doctype declaration).
    DocumentType = 10,
    /// A document fragment node.
    DocumentFragment = 11,
    /// A notation node.
    Notation = 12,
}

impl NodeType {
    /// Converts a `NodeType` to its string representation.
    /// Returns a string slice representing the type of the node.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Element => "Element",
            Self::Attribute => "Attribute",
            Self::Text => "Text",
            Self::CdataSection => "CDATASection",
            Self::EntityReference => "EntityReference",
            Self::Entity => "Entity",
            Self::ProcessingInstruction => "ProcessingInstruction",
            Self::Comment => "Comment",
            Self::Document => "Document",
            Self::DocumentType => "DocumentType",
            Self::DocumentFragment => "DocumentFragment",
            Self::Notation => "Notation",
        }
    }
}

#[cfg(test)]
mod ut_node_type {
    use crate::structure::NodeType;
    /*
     * @title  UT test for node as_str
     * @design Condition Coverage
     * @precon NA
     * @brief  1. Call NodeType。
     *         2. Call as_str to get content。
     *         3. Compare result
     * @expect 1. true。
     * @auto   yes
     */
    #[test]
    fn ut_node_type_as_str() {
        assert_eq!(NodeType::Element.as_str(), "Element");

        assert_eq!(NodeType::Attribute.as_str(), "Attribute");

        assert_eq!(NodeType::Text.as_str(), "Text");

        assert_eq!(NodeType::CdataSection.as_str(), "CDATASection");

        assert_eq!(NodeType::EntityReference.as_str(), "EntityReference");

        assert_eq!(NodeType::Entity.as_str(), "Entity");

        assert_eq!(
            NodeType::ProcessingInstruction.as_str(),
            "ProcessingInstruction"
        );

        assert_eq!(NodeType::Comment.as_str(), "Comment");

        assert_eq!(NodeType::Document.as_str(), "Document");

        assert_eq!(NodeType::DocumentType.as_str(), "DocumentType");

        assert_eq!(NodeType::DocumentFragment.as_str(), "DocumentFragment");

        assert_eq!(NodeType::Notation.as_str(), "Notation");
    }
}
